



import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:ip_check_demo/ArpPage.dart';
import 'package:ip_check_demo/pingPage/PingPage.dart';
import 'package:ip_check_demo/netSpeed/NetSpeedTest.dart';
import 'package:ip_check_demo/utils/IpUtils.dart';
import 'package:ip_check_demo/utils/hint_uitl.dart';
import 'package:ip_check_demo/utils/nav_util.dart';
import 'package:toast/toast.dart';

import 'ipChongTuCheck/IpCheckRangePage.dart';

class FuncsPage extends StatefulWidget{
  @override
  State<StatefulWidget> createState() {
    return _FuncsState();
  }

}

class _FuncsState extends State<FuncsPage>{
  String localIp = '';
  String macStr= '';

  @override
  void initState() {
    initLocalIp();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {

    ToastContext().init(context);
    return Scaffold(
      appBar: AppBar(
        title: Text("功能列表"),
      ),
      body:
          Center(
            child:
            Column(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                SizedBox(
                  height: 60,
                ),

                Container(
                  margin: EdgeInsets.all(8),
                  child: Text(
                    "本工具用以检测局域网内网络通联，避免Ip使用冲突等"
                    ,
                    style: TextStyle(
                        color: Colors.blue
                    ),
                  ),
                ),
                Container(

                  margin: EdgeInsets.all(8),
                  child: Text(
                    '你的地址：$localIp',
                    style: TextStyle(
                        color: Colors.blue
                    ),
                  ),
                ),

                Container(
                  margin: EdgeInsets.all(8),
                  child:     ElevatedButton(
                    child: Text("Ip占用检测"),
                    onPressed: () {
                      naviIpChecked();
                    },
                    onLongPress: (){
                      HintUtil.toast("检测局域网内Ip是否占用，已使用的会标为绿色");
                    },
                    style: ElevatedButton.styleFrom(
                      minimumSize: const Size(200, 50),
                      // shape:
                      // RoundedRectangleBorder(borderRadius: BorderRadius.circular(10))
                    ),

                  ),
                ),

                Container(
                  margin: EdgeInsets.all(8),
                  child:
                  ElevatedButton(
                      child: Text("Ping一下"),
                      onPressed: () {
                        naviPingIp();
                      },
                      onLongPress: (){
                        HintUtil.toast("网络检测基础Ping一下吧");
                      },
                      style: ElevatedButton.styleFrom(
                        minimumSize: const Size(200, 50),
                      )
                  ),
                ),
                Container(
                  margin: EdgeInsets.all(8),
                  child:
                  ElevatedButton(
                      child: Text("网络测速"),
                      onPressed: () {
                        naviNetSpeed();
                      },
                      onLongPress: (){
                        HintUtil.toast("网络检测基础Ping一下吧");
                      },
                      style: ElevatedButton.styleFrom(
                        minimumSize: const Size(200, 50),
                      )
                  ),
                ),
              ],
            ),
          ),

    );
  }
  Future<void> initLocalIp() async {
    print('start get ip');
    String? ip = await IpUtils.getLocalIpAddress();

    setState(() {
      localIp = ip!;
    });

    print(ip);

  }


  naviPingIp(){
    NavUtil.navTo(context, PingPage());
  }

  naviIpChecked(){
    NavUtil.navTo(context, IpCheckRangePage(title: "Ip占用检测"));
  }

  naviNetSpeed(){
    NavUtil.navTo(context, NetSpeedPage());
  }


}